package cn.wolfcode.luowowo.acticle.service.impl;

import cn.wolfcode.luowowo.acticle.domain.TravelCommend;
import cn.wolfcode.luowowo.acticle.mapper.TravelCommendMapper;
import cn.wolfcode.luowowo.acticle.query.TravelCommendQueryObject;
import cn.wolfcode.luowowo.acticle.service.ITravelCommendService;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * 游记推荐服务实现类
 */
@Service
public class TravelCommendServiceImpl implements ITravelCommendService {
    @Autowired
    private TravelCommendMapper travelCommendMapper;
    //查询所有游记推荐
    @Override
    public PageInfo query(TravelCommendQueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize());
        List<TravelCommend> list = travelCommendMapper.selectForList(qo);
        return new PageInfo(list);
    }

    //删除游记推荐
    @Override
    public void delete(Long id) {
        travelCommendMapper.deleteByPrimaryKey(id);
    }
    //保存/更新
    @Override
    public void saveOrUpdate(TravelCommend travelCommend) {
        if(travelCommend.getId() != null){
            travelCommendMapper.updateByPrimaryKey(travelCommend);
        }else{
            travelCommendMapper.insert(travelCommend);
        }
    }

    @Override
    public List<TravelCommend> getCommentTop5() {
        return travelCommendMapper.selectCommentTop5();
    }

    //查询所有游记推荐
    @Override
    public List<TravelCommend> list() {
        return travelCommendMapper.selectAll();
    }

}
